var app = getApp();
//封装接口请求方法
export const com = {
  req(url, data, method, cb, authorization) {
    wx.request({
      url: url,
      data: data,
      method: method,
      success: function (res) {
        if (res.data.code == 501) {
          wx.setStorageSync('kpToken', '');
        }
        return typeof cb == "function" && cb(res.data)
      },
      fail: function () {
        return typeof cb == "function" && cb(false)
      }
    })
  },

  isLogin() {
    // 判断如果为空，跳转到登录页面
    var userid = wx.getStorageSync('kpUserId') || [];
    if (userid == '' || Object.prototype.toString.call(userid) === '[object Undefined]') {

      // wx.navigateTo({
      //   url: '/pages/login/login'
      // })
    }
  },
  
  getCode(_this, num) {
  _this.setData({
    isShow: true  
  })
  var remain = num;   
  var time = setInterval(function () {
    if (remain == 1) {
      clearInterval(time);
      _this.setData({
        sec: num,
        isShow: false
      })
      return false //必须有
    }
    remain--;
    _this.setData({
      sec: remain
    })
  }, 1000)
},
 errorTost(txt) {
    wx.showToast({
      title: txt,
      icon: 'error',
      image: '../../../images/login/error.png',
    })
  }
}



